WireIt.WebUITerminal = function(parentEl, options, container){
//	WireIt.WebUITerminal.superclass.constructor.call(this, parentEl, options, container);
	
	var util = YAHOO.util;
	var Event = util.Event, lang = YAHOO.lang, Dom = util.Dom, CSS_PREFIX = "WireIt-";
   
   /**
    * DOM parent element
    * @property parentEl
    * @type {HTMLElement}
    */
   this.parentEl = parentEl;
   
   /**
    * Container (optional). Parent container of this terminal
    * @property container
    * @type {WireIt.Container}
    */
   this.container = container;
   
   /**
    * List of the associated wires
    * @property wires
    * @type {Array}
    */
    this.wires = [];
   
   
   this.setOptions(options);
   
   /**
    * Event that is fired when a wire is added
    * You can register this event with myTerminal.eventAddWire.subscribe(function(e,params) { var wire=params[0];}, scope);
    * @event eventAddWire
    */
   this.eventAddWire = new util.CustomEvent("eventAddWire");
   
   /**
    * Event that is fired when a wire is removed
    * You can register this event with myTerminal.eventRemoveWire.subscribe(function(e,params) { var wire=params[0];}, scope);
    * @event eventRemoveWire
    */
   this.eventRemoveWire = new util.CustomEvent("eventRemoveWire");
   
   /**
    * DIV dom element that will display the Terminal
    * @property el
    * @type {HTMLElement}
    */
   this.el = null;
   
   
   this.render();

	if(this.options.editable) {
      this.dd = new WireIt.WebUITerminalProxy(this, this.options.ddConfig);
	  //alert("new");
      this.scissors = new WireIt.Scissors(this);
   }
};

YAHOO.lang.extend(WireIt.WebUITerminal, WireIt.Terminal, {

});

WireIt.WebUITerminalProxy = function(terminal, options){
	WireIt.WebUITerminalProxy.superclass.constructor.call(this,terminal, options);
};

YAHOO.lang.extend(WireIt.WebUITerminalProxy,WireIt.TerminalProxy,{
/**
 * @method isValidWireTerminal
 */
isValidWireTerminal: function(DDterminal) {

      if( !DDterminal.isWireItTerminal ) {
         return false;
      }
      
      // If this terminal has the type property:
      if(this.termConfig.type) {
         if(this.termConfig.allowedTypes) {
			if(DDterminal.terminal.container == this.terminal.container) {
               return false;
            }
			if (this.termConfig.allowedTypes.indexOf("input:any")> -1){
				if (DDterminal.termConfig.type.split(":")[0]=="input"){
					return true;
				}
				else {
					return false
				}
			}
			if (this.termConfig.allowedTypes.indexOf("output:any")> -1){
				if (DDterminal.termConfig.type.split(":")[0] == "output") {
					return true;
				}
				else {
					return false
				}
			}
			else if( WireIt.indexOf(DDterminal.termConfig.type, this.termConfig.allowedTypes) == -1 ) {
			   return false;
            }

         }
         else {
            if(this.termConfig.type != DDterminal.termConfig.type) {
			   return false;
            }
         }
      }
      // The other terminal may have type property too:
      else if(DDterminal.termConfig.type) {
         if(DDterminal.termConfig.allowedTypes) {
			if(DDterminal.terminal.container == this.terminal.container) {
               return false;
            }			
			if (DDTerminal.termConfig.allowedTypes.indexOf("input:any")> -1){
				if (this.termConfig.type.split(":")[0]=="input"){
					return true;
				}
				else {
					return false
				}
			}
			if (DDTerminal.termConfig.allowedTypes.indexOf("output:any")> -1){
				if (this.termConfig.type.split(":")[0]=="output"){
					return true;
				}
				else {
					return false
				}
			}
            else if( WireIt.indexOf(this.termConfig.type, DDterminal.termConfig.allowedTypes) == -1 ) {
               return false;
            }

         }
         else {
            if(this.termConfig.type != DDterminal.termConfig.type) {
               return false;
            }
         }
      }
      
      // Check the allowSelfWiring
      if(this.terminal.container) {
         if(this.terminal.container.options.preventSelfWiring) {
            if(DDterminal.terminal.container == this.terminal.container) {
               return false;
            }
         }
      }
      
      return true;
}

});